package com.zzy.blog.http.test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

/**
 * httpclient传输字符串
 * @author eason
 *
 */
public class ClientBasic {
	
	private static final String LOING_URL = "http://localhost:8080/SSHDemo/server";

	public static void main(String[] args) throws ClientProtocolException, IOException {
		HttpClient client = new DefaultHttpClient();
		HttpPost httpost = new HttpPost(LOING_URL);
		
		List<NameValuePair> parameters = new ArrayList<NameValuePair>();
		parameters.add(new BasicNameValuePair("user.name", "sasa"));
		parameters.add(new BasicNameValuePair("user.password", "sasasa"));
		httpost.setEntity(new UrlEncodedFormEntity(parameters, HTTP.UTF_8));
		
		HttpResponse response = client.execute(httpost);
		
		HttpEntity entity = response.getEntity();
		String responseHtml = EntityUtils.toString(entity);
		
		System.out.println(responseHtml);
	}

}
